#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int Sum(int size)
    {
        int sum = 0;
        while (size)
        {
            sum += pow(size % 10, 2);
            size /= 10;
        }
        return sum;
    }

    bool isHappy(int n) {
        int slow = n;
        int fast = Sum(n);
        while (slow != fast)
        {
            slow = Sum(slow);
            fast = Sum(Sum(fast));
        }
        return fast == 1;
    }
};